package model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class CustomerList implements Serializable, Collection<Customer> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 480724022069548605L;
	private ArrayList<Customer> list;
	
	/**
	 * constructor
	 */
	public CustomerList(){
		list = new ArrayList<Customer>();
	}
	
	/**
	 * constructor
	 * @param A collection of Customers
	 */
	public CustomerList(Collection<Customer> c){
		list = new ArrayList<Customer>(c);
	}
	
	/**
	 * constructor
	 * @param the initial size of the list
	 */
	public CustomerList(int i){
		list = new ArrayList<Customer>(i);
	}
	
	
	@Override
	public boolean add(Customer arg0) {
		return list.add(arg0);
	}

	@Override
	public boolean addAll(Collection<? extends Customer> arg0) {
		return list.addAll(arg0);
	}

	@Override
	public void clear() {
		list.clear();
	}

	@Override
	public boolean contains(Object arg0) {
		return list.contains(arg0);
	}

	@Override
	public boolean containsAll(Collection<?> arg0) {
		return list.containsAll(arg0);
	}

	@Override
	public boolean isEmpty() {
		return list.isEmpty();
	}

	@Override
	public Iterator<Customer> iterator() {
		return list.iterator();
	}

	@Override
	public boolean remove(Object arg0) {
		return list.remove(arg0);
	}

	@Override
	public boolean removeAll(Collection<?> arg0) {
		return list.removeAll(arg0);
	}

	@Override
	public boolean retainAll(Collection<?> arg0) {
		return list.retainAll(arg0);
	}

	@Override
	public int size() {
		return list.size();
	}

	@Override
	public Object[] toArray() {
		return list.toArray();
	}

	@Override
	public <T> T[] toArray(T[] arg0) {
		return list.toArray(arg0);
	}
	
	/**
	 * get
	 * @param a customer id
	 * @return a Customer
	 * 
	 * description: performs a linear search for the customer matching
	 * this customer id in the list.
	 */
	public Customer get(String custid){
		Iterator<Customer> iterator = list.iterator();
		
		while(iterator.hasNext()){
			Customer customer = iterator.next();
			if(customer.getCustId().equals(custid))
				return customer;
		}
		
		return null;
	}
}
